package com.xuanwei.admin.controller;

import com.xuanwei.core.response.ResultVO;
import com.xuanwei.core.service.IXwNoticeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;

/**
 * @Author jiangyong
 * @Description TODO
 * @Date 2019/8/7 15:00
 **/
@RestController
@RequestMapping("api/notice")
@Validated
public class NoticeController extends BasicController {

    private IXwNoticeService noticeService;

    public NoticeController(IXwNoticeService noticeService) {
        this.noticeService = noticeService;
    }

    @RequestMapping(value = "add.do", method = RequestMethod.GET)
    public ResultVO add(Integer id,
                        @NotBlank(message = "内容不能为空") String content,
                        @RequestParam(defaultValue = "0") Integer orderBy) {
        noticeService.add(id, content, orderBy);
        return ResultVO.successResult("保存成功");
    }

    @RequestMapping(value = "list.do", method = RequestMethod.GET)
    public ResultVO list() {
        return ResultVO.successResult(noticeService.findAll());
    }

    @RequestMapping(value = "delete.do", method = RequestMethod.GET)
    public ResultVO del(@Min(value = 1,message = "ID格式错误") Integer id) {
        noticeService.del(id);
        return ResultVO.successResult("删除成功");
    }
}
